﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.DAL
{
    public class StockOutTypeDAL:IStockOutTypeDAL
    {
        #region IStockOutTypeDAL 成员

        public IDataReader Select()
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_StockOutType_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public IDataReader Select(int StockOutTypeNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_StockOutType_Select", new SqlParameter[] { new SqlParameter("@StockOutTypeNum", StockOutTypeNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }      
        }

        public IDataReader Select(string StockOutTypeName)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_StockOutType_Select_By_Name", new SqlParameter[] { new SqlParameter("@StockOutTypeName", StockOutTypeName) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }      
        }

        public DataTable SelectAll()
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockOutType_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Insert(string StockOutTypeName, string StockOutTypeCode)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockOutTypeName",StockOutTypeName),
                    new SqlParameter("@StockOutTypeCode",StockOutTypeCode)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutType_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Update(int StockOutTypeNum, string StockOutTypeName,string StockOutTypeCode)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockOutTypeNum",StockOutTypeNum),
                    new SqlParameter("@StockOutTypeName",StockOutTypeName),
                    new SqlParameter("@StockOutTypeCode",StockOutTypeCode)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutType_Update", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }    
        }

        public int Delete(int StockOutTypeNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutType_Delete", new SqlParameter[] { new SqlParameter("@StockOutTypeNum", StockOutTypeNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }     
        }

        #endregion
    }
}
